var express = require('express');
var router = express.Router();
var request = require('request')

/* GET home page. */
router.post('/', function(req, res, next) {
  let url = decodeURIComponent(req.body.url)
  let data = req.body.params

  const options = {
    uri: url,
    method: 'post',
    headers: {
      'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
      'Content-Type': 'text/html; charset=UTF-8',
      'Host': 'i.waimai.meituan.com',
      'Referer': 'http://i.waimai.meituan.com',
      'Cookie': ''
    },
    form: data
  }

  request(options, function(error, response, body){
    try{
      res.json(JSON.parse(body))
    }catch(e){
      res.json()
    }
  })
});

module.exports = router;
